<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./libs/vue3.js"></script>
    <style>
        .home{
            background-color: orange;
            padding: 10px;
        }
    </style>
</head>
<body>
    <div id="app">
        <home v-if="visible"></home>
        <hr>
        <button @click="visible=!visible">toggle</button>
    </div>
</body>
<script>
    const app=Vue.createApp({
        data(){
            return {
                // 控制home组件的显示状态
                visible:true
            }
        }
    });
    // 注册全局组件
    app.component('home',{
        template:`
            <div class="home">
                <h1>{{title}}</h1>
                <button @click="title='new title'">update title</button>
            </div>
        `,
        data(){
            return {
                title:'组件生命周期钩子函数'
            }
        },
        // 创建阶段
        beforeCreate(){
            console.log('beforeCreate');
        },
        created(){
            console.log('created');
        },
        // 挂载阶段
        beforeMount(){
            console.log('beforeMount');
        },
        mounted(){
            console.log('mounted');
        },
        // 运行阶段
        beforeUpdate(){
            console.log('beforeUpdate');
        },
        updated(){
            console.log('updated');
        },
        // 卸载阶段
        beforeUnmount(){
            console.log('beforeUnmount');
        },
        unmounted(){
            console.log('unmounted');
        }
    });

    // 挂载vue应用
    app.mount('#app');
</script>
</html>